/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import bc.DimensionpapelFacadeLocal;
import be.Dimensionpapel;
import be.Gramaje;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.model.SelectItem;
import javax.inject.Named;

/**
 *
 * @author yzavaleta
 */
@Named("managedBeanDimensionPapel")
@SessionScoped
public class ManagedBeanDimensionPapel implements Serializable {

    @EJB
    private DimensionpapelFacadeLocal dimensionpapelFacade;
    private Dimensionpapel objeto;
    private Dimensionpapel objetoCrear;
    private List<Dimensionpapel> lista;
    private List<Dimensionpapel> listaFiltrada;
    private List<SelectItem> ListaItems = new LinkedList<SelectItem>();
    private HashMap<Integer, Dimensionpapel> myMapItems = new HashMap<Integer, Dimensionpapel>();

    public ManagedBeanDimensionPapel() {
    }

    public Dimensionpapel getObjeto() {
        return objeto;
    }

    public void setObjeto(Dimensionpapel objeto) {
        this.objeto = objeto;
    }

    public Dimensionpapel getObjetoCrear() {
        return objetoCrear;
    }

    public void setObjetoCrear(Dimensionpapel objetoCrear) {
        this.objetoCrear = objetoCrear;
    }

    public List<Dimensionpapel> getLista() {

        lista = new LinkedList<>();
        for (Dimensionpapel a : dimensionpapelFacade.findAll()) {

            if (a.getEstadoExistencia() == 1) {
                lista.add(a);
            }

        }
        return lista;
    }

    public void setLista(List<Dimensionpapel> lista) {
        this.lista = lista;
    }

    public List<Dimensionpapel> getListaFiltrada() {
        return listaFiltrada;
    }

    public void setListaFiltrada(List<Dimensionpapel> listaFiltrada) {
        this.listaFiltrada = listaFiltrada;
    }

    public List<SelectItem> getListaItems() {
        ListaItems = new LinkedList<SelectItem>();
        myMapItems = new HashMap<Integer, Dimensionpapel>();

        for (Dimensionpapel p : dimensionpapelFacade.findAll()) {

            if (p.getEstadoExistencia() == 1) {
                myMapItems.put(p.getId(), p);

                ListaItems.add(new SelectItem(p, p.getCodigo()+" - " +p.getDescripcion()));

            }

        }
        return ListaItems;
    }

    public void setListaItems(List<SelectItem> ListaItems) {
        this.ListaItems = ListaItems;
    }

    public HashMap<Integer, Dimensionpapel> getMyMapItems() {
        return myMapItems;
    }

    public void setMyMapItems(HashMap<Integer, Dimensionpapel> myMapItems) {
        this.myMapItems = myMapItems;
    }

    public void llenar_myItems() {
        try {
            myMapItems = new HashMap<Integer, Dimensionpapel>();
            for (Dimensionpapel p : dimensionpapelFacade.findAll()) {
                if (p.getEstadoExistencia() == 1) {
                    myMapItems.put(p.getId(), p);
                    ListaItems.add(new SelectItem(p, p.getCodigo()));
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Dimensionpapel getObjeto(int id) {
        return myMapItems.get(id);
    }
}
